<template>
	<div>
		<basic-container>
			<avue-crud :option="option4" :data="data" :page.sync="page" @size-change="sizeChange"
				@current-change="currentChange">
			</avue-crud>
		</basic-container>
	</div>


</template>

<script>
	import {
		mapGetters
	} from "vuex";
	import request from '@/router/axios';
	import {
		baseUrl
	} from '@/config/env';

	export default {
		name: "wel",
		props: {
			id: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				dic: [],
				searchText: "",
				data: [],
				type: '',
				box: false,
				page: {
					currentPage: 1,
					total: 0,
					layout: "total,pager,prev, next",
					background: false,
					pageSize: 10
				},
				delval: null,
			};
		},
		computed: {
			...mapGetters(["userInfo"]),
			option4() {

				return {
					addBtn: false,
					delBtn: false,
					menu: false,
					editBtn: false,
					//index: true,
					align: 'center',
					menuAlign: 'center',
					column: [{
							label: this.$t("wel.table.code"),
							prop: "code",
							//editDisabled:true,
						},
						{
							label: this.$t("wel.table.connectionType"),
							prop: "connectionType",

						},
						{
							label: this.$t("wel.table.devname"),
							prop: "deviceName",

						},
						{
							label: this.$t("wel.table.time"),
							prop: "create_time",
						}

					]
				};
			}
		},
		created() {
			console.log(this.id);
			this.getList({
				'id': this.id,
				'page': 1,
				'pageSize': this.page.pageSize
			});
			this.getContent();
		},
		methods: {

			sizeChange(val) {
				this.page.currentPage = 1
				this.page.pageSize = val
				this.getList()
			},

			currentChange(val) {
				this.page.currentPage = val
				this.getList({
					'page': val,
					'id': this.id,
					'pageSize': this.page.pageSize
				});
			},
			delChange(val, index) {
				let that = this;
				this.box = true;
				this.delval = val;
				return;

			},
			getContent(data) {
				return;
				let that = this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + '/userapi/Equipment/getAllContent',
						data: data
					})
					.then(function(response) {
						if (response.data.status == 0) {
							that.$message.error(response.data.info)
						} else if (response.data.status == 1) {
							that.dic.length = 0;
							response.data.data.forEach(function(item, index) {
								var newitem = {
									label: item.name,
									value: item.name,
									children: []
								};
								item.content.forEach(function(contentItem, contentIndex) {
									newitem.children.push({
										label: contentItem.name,
										desc: contentItem.code,
										value: contentItem.id
									});
								})
								console.log(newitem);
								that.dic.push(newitem);
							})

						}

					})
					.catch(function(error) {
						console.log(error);
						that.$message.error('系统错误')
					});

			},


			getList(data) {
				let that = this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + '/api/log/getList',
						data: data
					})
					.then(function(response) {
						if (response.data.status == 0) {
							that.$message.error(response.data.info)
						} else if (response.data.status == 1) {
							response.data.data.data.forEach(function(item, index) {
								var params = JSON.parse(item.params);
								response.data.data.data[index].connectionType = item.type ==1?
									that.$t("wel.table.goOnline") : that.$t("wel.table.off_line");
								response.data.data.data[index].clientId = item.code;
								response.data.data.data[index].deviceName = item.devname;
							})
							that.data = response.data.data.data;
							that.page.total = response.data.data.total;
							that.page.pageSize = response.data.data.per_page;
						}
					})
					.catch(function(error) {
						that.$message.error('系统错误')
					});

			}
		}
	};
</script>

<style scoped="scoped" lang="scss">
	.wel {
		&__header {
			padding: 25px 40px;
			border-bottom: 1px solid #e8e8e8;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		&__info {
			display: flex;
			align-items: center;

			&-img {
				border-radius: 72px;
				display: block;
				width: 72px;
				height: 72px;

				img {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			&-content {
				position: relative;
				margin-left: 24px;
				color: rgba(0, 0, 0, 0.45);
				line-height: 22px;
			}

			&-title {
				font-size: 20px;
				line-height: 28px;
				font-weight: 500;
				color: rgba(0, 0, 0, 0.85);
				margin-bottom: 12px;
			}

			&-subtitle {
				position: relative;
				font-size: 14px;
				color: rgba(0, 0, 0, 0.45);
				line-height: 22px;
			}
		}

		&__extra {
			&-item {
				position: relative;
				padding: 0 32px;
				display: inline-block;

				&:last-child {
					&::after {
						display: none;
					}
				}

				&:after {
					background-color: #e8e8e8;
					position: absolute;
					top: 30px;
					right: 0;
					width: 1px;
					height: 40px;
					content: "";
				}
			}

			&-title {
				color: rgba(0, 0, 0, 0.45);
				font-size: 14px;
				line-height: 22px;
				margin-bottom: 4px;
			}

			&-subtitle {
				color: rgba(0, 0, 0, 0.85);
				font-size: 30px;
				line-height: 38px;
				margin: 0;

				span {
					color: rgba(0, 0, 0, 0.45);
					font-size: 20px;
				}
			}
		}
	}
</style>
